<?php
/**
 * @author Zwc
 * Created On 2021/2/21 13:42
 */

namespace app\auth\service;


class MenuFormat
{

    public static function formatMenu($cate , $lefthtml = '--' , $pid=0 , $lvl=0, $leftpin=0 ){
        $arr = [];
        foreach ($cate as $v){
            if($v['pid']==$pid){
                $v['lvl']=$lvl + 1;
                $v['leftpin']=$leftpin + 0;//左边距
                $v['lefthtml'] = str_repeat($lefthtml,$lvl);
                $arr[]=$v;
                $arr= array_merge($arr,self::formatMenu($cate,$lefthtml,$v['id'],$lvl + 1 , $leftpin+20));
            }
        }
        return $arr;
    }
}